<template>
	<view class="content">
		<view class="xuaz" @click="jumpPage(1)">
			<view class="lable-name" style="width: 20%;">实名认证</view>
			<view class="lable-select" style="width: 80%;">></view>
		</view>
		<view class="xuaz" @click="jumpPage(2)">
			<view class="lable-name" style="width: 20%;">登录密码</view>
			<view class="lable-select" style="width: 80%;">></view>
		</view>
		<view class="xuaz" @click="jumpPage(3)">
			<view class="lable-name" style="width: 20%;">交易密码</view>
			<view class="lable-select" style="width: 80%;">></view>
		</view>
		<view class="xuaz" @click="jumpPage(4)">
			<view class="lable-name" style="width: 20%;">收款设置</view>
			<view class="lable-select" style="width: 80%;">></view>
		</view>
		
		<view class="content" style="padding: 1rem;text-align: center;">
			<button style="width: 90%;background: #dd5154;color: white;height: 2.5rem; line-height: 2.5rem;" @click="logout()">安全退出</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user_info:null,
				user_token:null
			};
		},
		onLoad() {
			this.getUserInfo()
		},
		methods: {
			getUserInfo(){
				let that = this
				if(that.userInfo == null){
					uni.getStorage({
						key: 'user_token',
						success: function (res) {
							that.user_token = res.data
							that.checkUser()
						},
						fail: function(res){
							uni.showToast({
								title:'请先登录',
								icon:'none',
								success() {
									uni.redirectTo({
										url:'/pages/login/login',
									})
								}
							})
							
						}
					});
				}
			},
			checkUser(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + '/api/user/getUserInfo',
					method:'POST',
					header: {token:that.user_token},
					success(res) {
						if(res.data.code == 401){
							uni.removeStorage({
								key:'user_token',
								success() {
									uni.showToast({
										icon:'none',
										title:'登录已失效,请重新登录',
										success() {
											setTimeout(function(){
												uni.redirectTo({
													url:'/pages/login/login'
												})
											})
										}
									})
								}
							})
						}
						that.user_info = res.data.data
					},
					fail() {
						uni.showToast({
							title:'网络错误',
							icon:'none',
						})
					}
				})
			},
			jumpPage(data){
				switch(data){
					case 1:
						uni.navigateTo({
							url:"/pages/smrz/smrz"
						})
						break;
					case 2:
						uni.navigateTo({
							url:"/pages/loginPassword/loginPassword"
						})
						break;
					case 3:
						uni.navigateTo({
							url:"/pages/payPassword/payPassword"
						})
						break;
					default:
						uni.navigateTo({
							url:"/pages/myWalletInfo/myWalletInfo"
						})
						break;
					
				}
			},
			logout(){
				let that = this
				uni.request({
					url:getApp().globalData.baseUrl + '/api/user/logout',
					method:'POST',
					header:{
						token: that.user_token
					},
					success(res) {
						uni.showToast({
							title:res.data.msg,
							icon:'none',
							success(sres) {
								uni.removeStorage({
									key:'user_token',
									success() {
										uni.redirectTo({
											url:'/pages/login/login'
										})
									}
								})
								
							}
						})
					},
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
		background: #f4f4f4;
	}
	.xuaz{
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin: 0 0.6rem;
		padding: 1rem;
		border-bottom: 1px solid #f6f6f6 !important;
	}
	.lable-name{
		width: 30%;
		font-weight: bold;
		font-size: 14px;
	}
	.lable-select{
		width: 60%;
		display: flex;
		    justify-content: end;
	}
	.content{
		background: #fff;
		display: flex;
		flex-direction: column;
		margin-top: .7rem;
	}
	
	.lable-select >input{
		width: 100%;
	}
</style>
